<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"/>

  <xsl:template match="root">
    <xsl:for-each select="s">
      <xsl:call-template name="s"></xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <xsl:template match="s" name="s"><xsl:call-template name="singlechar">
    <xsl:with-param name="n" select="c"></xsl:with-param>
  </xsl:call-template></xsl:template>
  <xsl:template match="c" name="c">
    <xsl:value-of select="*"/>
  </xsl:template>

  <xsl:template name="htmlencoding">
    <xsl:param name="n" select="n"></xsl:param>
    <xsl:choose>
      <xsl:when test="$n div 16 &gt;= 1">
        <xsl:call-template name="htmlencoding">
          <xsl:with-param name="n" select="floor($n div 16)"></xsl:with-param>
        </xsl:call-template>
        <xsl:call-template name="hexencoding">
          <xsl:with-param name="n" select="$n mod 16"></xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="hexencoding">
          <xsl:with-param name="n" select="$n mod 16"></xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="hexencoding">
    <xsl:param name="n" select="n"></xsl:param>
    <xsl:choose>
      <xsl:when test="$n=15">F</xsl:when>
      <xsl:when test="$n=14">E</xsl:when>
      <xsl:when test="$n=13">D</xsl:when>
      <xsl:when test="$n=12">C</xsl:when>
      <xsl:when test="$n=11">B</xsl:when>
      <xsl:when test="$n=10">A</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$n"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="singlechar">
    <xsl:param name="n" select="n"></xsl:param>
    <xsl:choose>
      <xsl:when test="$n=38">&amp;amp;</xsl:when>
      <xsl:when test="$n=60">&amp;lt;</xsl:when>
      <xsl:when test="$n=62">&amp;gt;</xsl:when>
      <xsl:when test="$n=33">!</xsl:when>
      <xsl:when test="$n=34">"</xsl:when>
      <xsl:when test="$n=35">#</xsl:when>
      <xsl:when test="$n=36">$</xsl:when>
      <xsl:when test="$n=37">%</xsl:when>
      <xsl:when test="$n=39">'</xsl:when>
      <xsl:when test="$n=40">(</xsl:when>
      <xsl:when test="$n=41">)</xsl:when>
      <xsl:when test="$n=42">*</xsl:when>
      <xsl:when test="$n=43">+</xsl:when>
      <xsl:when test="$n=44">,</xsl:when>
      <xsl:when test="$n=45">-</xsl:when>
      <xsl:when test="$n=46">.</xsl:when>
      <xsl:when test="$n=47">/</xsl:when>
      <xsl:when test="$n=48">0</xsl:when>
      <xsl:when test="$n=49">1</xsl:when>
      <xsl:when test="$n=50">2</xsl:when>
      <xsl:when test="$n=51">3</xsl:when>
      <xsl:when test="$n=52">4</xsl:when>
      <xsl:when test="$n=53">5</xsl:when>
      <xsl:when test="$n=54">6</xsl:when>
      <xsl:when test="$n=55">7</xsl:when>
      <xsl:when test="$n=56">8</xsl:when>
      <xsl:when test="$n=57">9</xsl:when>
      <xsl:when test="$n=58">:</xsl:when>
      <xsl:when test="$n=59">;</xsl:when>
      <xsl:when test="$n=61">=</xsl:when>
      <xsl:when test="$n=63">?</xsl:when>
      <xsl:when test="$n=64">@</xsl:when>
      <xsl:when test="$n=65">A</xsl:when>
      <xsl:when test="$n=66">B</xsl:when>
      <xsl:when test="$n=67">C</xsl:when>
      <xsl:when test="$n=68">D</xsl:when>
      <xsl:when test="$n=69">E</xsl:when>
      <xsl:when test="$n=70">F</xsl:when>
      <xsl:when test="$n=71">G</xsl:when>
      <xsl:when test="$n=72">H</xsl:when>
      <xsl:when test="$n=73">I</xsl:when>
      <xsl:when test="$n=74">J</xsl:when>
      <xsl:when test="$n=75">K</xsl:when>
      <xsl:when test="$n=76">L</xsl:when>
      <xsl:when test="$n=77">M</xsl:when>
      <xsl:when test="$n=78">N</xsl:when>
      <xsl:when test="$n=79">O</xsl:when>
      <xsl:when test="$n=80">P</xsl:when>
      <xsl:when test="$n=81">Q</xsl:when>
      <xsl:when test="$n=82">R</xsl:when>
      <xsl:when test="$n=83">S</xsl:when>
      <xsl:when test="$n=84">T</xsl:when>
      <xsl:when test="$n=85">U</xsl:when>
      <xsl:when test="$n=86">V</xsl:when>
      <xsl:when test="$n=87">W</xsl:when>
      <xsl:when test="$n=88">X</xsl:when>
      <xsl:when test="$n=89">Y</xsl:when>
      <xsl:when test="$n=90">Z</xsl:when>
      <xsl:when test="$n=91">[</xsl:when>
      <xsl:when test="$n=92">\</xsl:when>
      <xsl:when test="$n=93">]</xsl:when>
      <xsl:when test="$n=94">^</xsl:when>
      <xsl:when test="$n=95">_</xsl:when>
      <xsl:when test="$n=96">`</xsl:when>
      <xsl:when test="$n=97">a</xsl:when>
      <xsl:when test="$n=98">b</xsl:when>
      <xsl:when test="$n=99">c</xsl:when>
      <xsl:when test="$n=100">d</xsl:when>
      <xsl:when test="$n=101">e</xsl:when>
      <xsl:when test="$n=102">f</xsl:when>
      <xsl:when test="$n=103">g</xsl:when>
      <xsl:when test="$n=104">h</xsl:when>
      <xsl:when test="$n=105">i</xsl:when>
      <xsl:when test="$n=106">j</xsl:when>
      <xsl:when test="$n=107">k</xsl:when>
      <xsl:when test="$n=108">l</xsl:when>
      <xsl:when test="$n=109">m</xsl:when>
      <xsl:when test="$n=110">n</xsl:when>
      <xsl:when test="$n=111">o</xsl:when>
      <xsl:when test="$n=112">p</xsl:when>
      <xsl:when test="$n=113">q</xsl:when>
      <xsl:when test="$n=114">r</xsl:when>
      <xsl:when test="$n=115">s</xsl:when>
      <xsl:when test="$n=116">t</xsl:when>
      <xsl:when test="$n=117">u</xsl:when>
      <xsl:when test="$n=118">v</xsl:when>
      <xsl:when test="$n=119">w</xsl:when>
      <xsl:when test="$n=120">x</xsl:when>
      <xsl:when test="$n=121">y</xsl:when>
      <xsl:when test="$n=122">z</xsl:when>
      <xsl:when test="$n=123">{</xsl:when>
      <xsl:when test="$n=124">|</xsl:when>
      <xsl:when test="$n=125">}</xsl:when>
      <xsl:when test="$n=126">~</xsl:when>
      <xsl:otherwise>&amp;#x<xsl:call-template name="htmlencoding">
          <xsl:with-param name="n" select="$n"></xsl:with-param>
        </xsl:call-template>;</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
